package com.daocao.yfb.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import butterknife.BindView;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;
import com.daocao.yfb.R;
import com.daocao.yfb.api.model.NoticeIndexModel;
import com.daocao.yfb.util.DateTime;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class MsgTipsAdapter extends ItemAdapter<NoticeIndexModel.DatasBean.ListBean, MsgTipsAdapter.DefaultHolder> {

    private Context context;

    public MsgTipsAdapter(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_msg_tips, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        NoticeIndexModel.DatasBean.ListBean item = getItem(position);
        Glide.with(context).load(item.avatar).into(holder.imgIcon);
        holder.txtName.setText(item.name);
        holder.txtContent.setText(item.content);
        holder.txtTime.setText(DateTime.toDate(item.created_at*1000));
        if (item.msg_num == 0) {
            holder.txtOrderMsg.setVisibility(View.GONE);
        } else {
            holder.txtOrderMsg.setVisibility(View.VISIBLE);
            holder.txtOrderMsg.setText(item.msg_num+"");
        }
    }

    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.img_icon)
        CircleImageView imgIcon;
        @BindView(R.id.txt_order_msg)
        TextView txtOrderMsg;
        @BindView(R.id.txt_name)
        TextView txtName;
        @BindView(R.id.txt_content)
        TextView txtContent;
        @BindView(R.id.txt_time)
        TextView txtTime;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
